package com.unittec.drainage.provider.manage.common.mybatisTypeHandler;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author CopySun
 * @date 2020/9/11 13:34
 */
@MappedJdbcTypes(JdbcType.VARCHAR)
@MappedTypes({Boolean.class})
public class BoolbeanToVarcharTypeHandler implements TypeHandler<Boolean> {

    @Override
    public void setParameter(PreparedStatement ps, int i, Boolean aBoolean, JdbcType jdbcType) throws SQLException {
        if (aBoolean) {
            ps.setString(i,"1");
        } else {
            ps.setString(i,"0");
        }
    }

    @Override
    public Boolean getResult(ResultSet resultSet, int i) {
        return null;
    }

    @Override
    public Boolean getResult(ResultSet resultSet, String s) {
        return null;
    }

    @Override
    public Boolean getResult(CallableStatement callableStatement, int i) {
        return null;
    }
}
